<template>
  <!-- :collapse 绑定collaps属性 当属性是false是会折叠起来 -->
  <el-menu
    :collapse="isCollapse"
    class="el-menu-vertical-demo"
    active-text-color="#23aaf2"
    background-color="#545c64"
    text-color="#f8f8f2"
  >
    <div class="xd-icon">
      <img src="../assets/xd-icon.png" alt="xd-icon" />
      <span>图书管理系统</span>
    </div>

    <el-sub-menu index="1">
      <template #title>
        <el-icon><Document /></el-icon>
        <span>课程管理</span>
      </template>
      <el-menu-item index="1-1" @click="courseHandle('front')">前端课程</el-menu-item>
      <el-menu-item index="1-2" @click="courseHandle('back')">后端课程</el-menu-item>
      <el-menu-item index="1-3" @click="courseHandle('all')">全栈课程</el-menu-item>
    </el-sub-menu>

    <el-sub-menu index="2">
      <template #title>
        <el-icon><Setting /></el-icon>
        <span>用户管理</span>
      </template>
      <el-menu-item index="2-1">用户一</el-menu-item>
      <el-menu-item index="2-2">用户二</el-menu-item>
    </el-sub-menu>
  </el-menu>
</template>
<script setup>
import { defineProps } from 'vue'; // 拿到父组件所传值的必须包
import emitter from '../utils/eventBus';

/**
 * 控制侧边栏的折叠和展开
 */
const { isCollapse } = defineProps(['isCollapse']);
/**
 * 点击类目tab触发课程列表重新获取 事件 需放在 onMounted 
 */
const courseHandle = (category) => {
  emitter.emit('course', category);
};
</script>
<style lang="less" scoped>
.el-radio-button__inner {
  padding: 0;
}

.el-menu--collapse {
  border: none;
}

.el-menu:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
  border: none;
  user-select: none;
}

.xd-icon {
  display: flex;
  align-items: center;
  font-weight: 600;
  height: 60px;
  background-color: #fff;
  white-space: nowrap;
  padding-left: 15px;

  img {
    width: 45px;
    height: 40px;
    margin-right: 10px;
  }
}
</style>
